import 'package:dio/dio.dart';

import '../helper/dioHelper2.dart';

class Danger2 {
  int ID;
  String Guid;
  String Level;
  String Title;
  String Content;
  String Gps1;
  String Deal;
  String DealUser;
  String DealResult;
  String DealTM;
  int State;
  String CreateTM;
  String CheckTM;
  String CreateUser;
  String CheckUser;
  String CheckQM;
  String CheckQMTM;
  String Remarks;

  Danger2(
      this.ID,
      this.Guid,
      this.Level,
      this.Title,
      this.Content,
      this.Gps1,
      this.Deal,
      this.DealUser,
      this.DealResult,
      this.DealTM,
      this.State,
      this.CreateTM,
      this.CheckTM,
      this.CreateUser,
      this.CheckUser,
      this.CheckQM,
      this.CheckQMTM,
      this.Remarks);

  Danger2.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        Level = json["Level"],
        Title = json["Title"],
        Content = json["Content"],
        Gps1 = json["Gps1"],
        Deal = json["Deal"],
        DealUser = json["DealUser"],
        DealResult = json["DealResult"],
        DealTM = json["DealTM"],
        State = json["State"],
        CreateTM = json["CreateTM"],
        CheckTM = json["CheckTM"],
        CreateUser = json["CreateUser"],
        CheckUser = json["CheckUser"],
        CheckQM = json["CheckQM"],
        CheckQMTM = json["CheckQMTM"],
        Remarks = json["Remarks"];

  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'Level': Level,
        'Title': Title,
        'Content': Content,
        'Gps1': Gps1,
        'Deal': Deal,
        'DealUser': DealUser,
        'DealResult': DealResult,
        'DealTM': DealTM,
        'State': State,
        'CreateTM': CreateTM,
        'CheckTM': CheckTM,
        'CreateUser': CreateUser,
        'CheckUser': CheckUser,
        'CheckQM': CheckQM,
        'CheckQMTM': CheckQMTM,
        'Remarks': Remarks,
      };

  static Future<bool> Add(Danger2 x1) async {
    var response = await DioHelper.Post("/Danger2/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Danger2?> GetByID(int ID) async {
    var response =
        await DioHelper.Get("/Danger2/GetByID?ID=" + ID.toString(), {});

    if (response.statusCode == 200) return new Danger2.fromJson(response.data);
    return null;
  }

  static Future<bool> Update(Danger2 x1) async {
    var response = await DioHelper.Post("/Danger2/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(Danger2 x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/Danger2/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Danger2?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/Danger2/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new Danger2.fromJson(response.data);
    return null;
  }

  static Future<List<Danger2>> GetList(int pageIndex, int pageSize) async {
    Response response;

    response = await DioHelper.Get(
        "/Danger2/GetList?st=0&p1=" +
            pageIndex.toString() +
            "&ps=" +
            pageSize.toString(),
        {});

    var list1 = <Danger2>[];
    if (response.statusCode == 200) {
      //print(response.data);
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new Danger2.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<Danger2>> GetList2(int pageIndex, int pageSize) async {
    var response = await DioHelper.Get(
        "/Danger2/GetList?st=0&p1=" +
            pageIndex.toString() +
            "&ps=" +
            pageSize.toString(),
        {});

    var list1 = <Danger2>[];
    if (response.statusCode == 200) {
      //print(response.data);
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new Danger2.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<Danger2>> GetAllList() async {
    var response = await DioHelper.Get("/Danger2/GetAllList", {});
    var list1 = <Danger2>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new Danger2.fromJson(x));
      }
    }
    return list1;
  }
}
